home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
psstr108.zip
/
PASSTR.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-01-10
|
23KB
|
1,108 lines
{
Pascal String and Variable Procedures
Rev. 1.08
(c) Copyright 1993, Michael Gallias
Target: Real, Windows
Comment: Some procedures do work under Protected Mode, but not all of them.
To compile this with Turbo Pascal 6, simply remove the 'Const'
from the procedure defintions, e.g.
Procedure MyProc(Const MyVar:MyType);
becomes
Procedure MyProc(MyVar:MyType);
}
{$V-} {$B-}
Unit PasStr;
Interface
{$IFNDEF WINDOWS}
Uses CRT,Dos;
Const
MaxXYSaves = 5; {Max Number of Cursor Saves}
Type
XYType = (CursorX,CursorY);
XYPosData = Array[1..MaxXYSaves] of
Array [XYType] of Byte;
KeyBufferFunction = (Clear,Save,Restore);
{$ENDIF}
Const
LeftText = 0;
CentreText = 1;
CenterText = 1;
RightText = 2;
OutSideText = 3;
Type
TextFormats = LeftText..RightText;
JustifyFormats = LeftText..OutSideText;
CharSet = Set Of Char;
{$IFDEF WINDOWS}
Procedure FSplit (Path:String; Var Dir, Name, Ext:String);
{$ELSE}
Procedure SaveCursorSize(Var Data:Word);
Procedure RestCursorSize(Data:Word);
Procedure SaveXYPos (Var Position:XYPosData);
Procedure RestXYPos (Var Position:XYPosData);
Procedure CursorSize (UpLim,DownLim:Byte);
Procedure PushCursorSize;
Procedure PopCursorSize;
Procedure PushXYPos;
Procedure PopXYPos;
Procedure PushTextColor;
Procedure PopTextColor;
Procedure KeyBuffer (Option:KeyBufferFunction);
{$IFDEF MSDOS}
Function MemoryCount (P:Pointer):LongInt;
Procedure GetLowestOfs (P:Pointer; Var S,O:Word);
Procedure AdjustPtr (Var P:Pointer; Amount:LongInt);
{$ENDIF}
{$ENDIF}
Procedure SpacesToZeros (StIn:String; Var StOut:String);
Procedure RemoveLeading (StIn:String; Var StOut:String;
Const RemoveSet:CharSet);
Function PosFrom (SubS:String; StIn:String; FarIn:Byte):Byte;
Function RevPosFrom (SubS:String; StIn:String; FarIn:Byte):Byte;
Procedure UpperCase (StIn:String; Var StOut:String);
Procedure LowerCase (StIn:String; Var StOut:String);
Procedure CapWords (StIn:String; Var StOut:String);
Procedure PadVar (StIn:String; Var StOut:String; Count:Byte);
Procedure PadVarWith (StIn:String; Var StOut:String; Count:Byte;
WithMe:Char);
Procedure PadFileName (StIn:String; Var StOut:String);
Procedure FormatVar (StIn:String; Var StOut:String;
Size:Byte; Format:TextFormats);
Procedure UnPadVar (StIn:String; Var StOut:String);
Procedure UnPadVarRight (StIn:String; Var StOut:String);
Procedure UnPadVarLeft (StIn:String; Var StOut:String);
Procedure RightJustify (StIn:String; Var StOut:String;
Margin:Byte; JType:JustifyFormats);
Procedure ByteToHex (Decimal:Byte; Var Hex:String);
Procedure WordToHex (Decimal:Word; Var Hex:String);
Procedure LongIntToHex (Decimal:LongInt; Var Hex:String);
Function HexDigitValue (HexDigit:Char):Byte;
Procedure HexToByte (Hex:String; Var Decimal:Byte; Var Code:Integer);
Procedure HexToWord (Hex:String; Var Decimal:Word; Var Code:Integer);
Procedure HexToLongInt (Hex:String; Var Decimal:LongInt; Var Code:Integer);
Function Min (I, J:LongInt):LongInt;
Function Max (I, J:LongInt):LongInt;
Function AdjustMeter (StartMeter1,EndMeter1,ValueMeter1,
StartMeter2,EndMeter2:LongInt):LongInt;
Procedure SwapBytes (Var A,B:Byte);
Procedure SwapIntegers (Var A,B:Integer);
Procedure SwapWords (Var A,B:Word);
Procedure SwapLongInts (Var A,B:LongInt);
Procedure SwapReals (Var A,B:Real);
Procedure SwapStrings (Var A,B:String);
{$IFOPT N+}
Procedure SwapSingles (Var A,B:Single);
Procedure SwapDoubles (Var A,B:Double);
Procedure SwapExtendeds (Var A,B:Extended);
Procedure SwapComps (Var A,B:Comp);
{$ENDIF}
Implementation
{$IFDEF WINDOWS}
Procedure FSplit(Path:String; Var Dir, Name, Ext:String);
Var
LastSlash :Byte;
Begin
LastSlash:=RevPosFrom('\',Path,Length(Path));
If LastSlash=0 Then
Begin
LastSlash:=RevPosFrom(':',Path,Length(Path));
If LastSlash>0 Then
Begin {Found a Drive with Default Path}
Dir:=Copy(Path,1,LastSlash);
Delete(Path,1,LastSlash);
LastSlash:=0;
End
Else {No Drive, No Path}
Dir:='';
End
Else
Begin {A Path Found}
Dir:=Copy(Path,1,LastSlash);
Delete(Path,1,LastSlash); {Delete Directory}
End;
LastSlash:=Pos('.',Path);
If LastSlash>0 Then
Begin
Name:=Copy(Path,1,LastSlash-1);
Ext:=Copy(Path,LastSlash,Length(Path)-(LastSlash-1));
End
Else
Begin
Name:=Path;
Ext:='';
End;
If Length(Name)>8 Then Name:=Copy(Name,1,8);
If Length(Ext)>4 Then Ext:=Copy(Ext,1,4);
End;
{$ELSE}
Var
PushPopCursorSize:Array[1..MaxXYSaves] of Word;
PushPopTextColor :Array[1..MaxXYSaves] of Word;
PushPopCursorPos :XYPosData;
Procedure SaveCursorSize(Var Data:Word); Assembler;
Asm
mov ah,3
int 10h
les di,Data
mov es:[di],cx
End;
Procedure RestCursorSize(Data:Word); Assembler;
Asm
mov ah,1
mov cx,Data
int 10h
End;
Procedure SaveXYPos(Var Position:XYPosData);
{This saves the current cursor position and can store up to the last five}
{cursor positions}
{Number 'MaxXYSaves' is the lastest save}
Var
X:Byte; {Loop}
Begin
For X:=1 to MaxXYSaves-1 do {Shift Cursor Saves up}
Begin
Position[X,CursorX]:=Position[X+1,CursorX];
Position[X,CursorY]:=Position[X+1,CursorY];
End; {For X Loop}
Position[5,CursorX]:=WhereX; {Insert New Cursor Save Position}
Position[5,CursorY]:=WhereY;
End; {SaveXYPos}
Procedure RestXYPos(Var Position:XYPosData);
{This will restore up to five previously saved cursor positions}
{Number 'MaxXYSaves' is the position to be restored}
Var
X:Byte; {Loop}
Begin
GotoXY(Position[MaxXYSaves,CursorX],Position[MaxXYSaves,CursorY]); {Goto Old Position}
For X:=MaxXYSaves downto 2 do {Shift up the cursor positions for the next restore}
Begin
Position[X,CursorX]:=Position[X-1,CursorX];
Position[X,CursorY]:=Position[X-1,CursorY];
End; {For X Loop}
End; {RestXYPos}
Procedure CursorSize(UpLim,DownLim:Byte); Assembler;
{Set the cursor size. Send $20,$20 for no cursor}
Asm
mov ah,1
mov ch,UpLim
mov cl,DownLim
int 10h
End;
Procedure PushCursorSize;
Var
X:Word;
Begin
For X:=1 to MaxXYSaves-1 do
PushPopCursorSize[X]:=PushPopCursorSize[X+1];
Asm
mov ah,3
int 10h
mov X,cx
End;
PushPopCursorSize[MaxXYSaves]:=X;
End;
Procedure PopCursorSize;
Var
X:Word;
Begin
X:=PushPopCursorSize[MaxXYSaves];
Asm
mov ah,1
mov cx,X
int 10h
End;
For X:=MaxXYSaves DownTo 2 do
PushPopCursorSize[X]:=PushPopCursorSize[X-1];
End;
Procedure PushXYPos;
Var
X:Byte;
Begin
For X:=1 to MaxXYSaves-1 do
PushPopCursorPos[X]:=PushPopCursorPos[X+1];
PushPopCursorPos[MaxXYSaves,CursorX]:=WhereX;
PushPopCursorPos[MaxXYSaves,CursorY]:=WhereY;
End;
Procedure PopXYPos;
Var
X:Byte;
Begin
GotoXY(PushPopCursorPos[MaxXYSaves,CursorX],
PushPopCursorPos[MaxXYSaves,CursorY]);
For X:=MaxXYSaves DownTo 2 do
PushPopCursorPos[X]:=PushPopCursorPos[X-1];
End;
Procedure PushTextColor;
Var
X:Byte;
Begin
For X:=1 to MaxXYSaves-1 do
PushPopTextColor[X]:=PushPopTextColor[X+1];
PushPopTextColor[MaxXYSaves]:=TextAttr;
End;
Procedure PopTextColor;
Var
X:Word;
Begin
TextAttr:=PushPopTextColor[MaxXYSaves];
For X:=MaxXYSaves DownTo 2 do
PushPopTextColor[X]:=PushPopTextColor[X-1];
End;
Procedure KeyBuffer(Option:KeyBufferFunction);
Type
KeyBufType=Record
Head:Word;